<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>方法与事件的基本用法</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>

<body>
    <div id='app'>
        <p>点击数:{{counter}}</p>
        <button @click="counter++">点击</button>
        <hr>
        <!-- 在methods写方法 -->
        <p>点击数:{{counter}}</p>
        <button @click='handleAdd()'>+ 1</button>
        <button @click='handleAdd(10)'>+ 10</button>
        <hr>
        <!-- $event 表示的这个点击事件本身 -->
        <a href="http://www.apple.com" @click='handleClick("禁止打开",$event)'>打开链接</a>
    </div>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                counter: 0,
            },
            methods: {
                handleAdd: function(count) {
                    count = count || 1;
                    // this指向当前Vue实例app
                    this.counter += count;
                },
                // message[信息] ,event[事件]  
                handleClick: function(message, event) {
                    // preventDefault[阻止原本作用]
                    // event[打开事件本身] 被禁止 
                    event.preventDefault();
                    // 弹出消息框
                    window.alert(message);
                }
            }
        })
    </script>
</body>

</html>